package com.chat.biz.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chat.api.dto.AuthSetDTO;
import com.chat.api.entity.ChatBlack;
import com.chat.api.entity.User;
import com.chat.biz.mapper.UserInfoMapper;
import com.chat.common.exception.CommonException;
import com.chat.common.result.ResultEnum;
import com.chat.common.threadLocal.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
*功能：
 作者：chenhao
*日期： 2025/6/7 下午4:41
*/
@Service
public class UserInfoService extends ServiceImpl<UserInfoMapper, User> {
    @Autowired
    private BlackService blackService;
    public User details() {
        String userId = UserContext.getUserId().getUserId();
        return baseMapper.selectById(userId);
    }

    public void setMyinformation(AuthSetDTO dto) {
        User user = baseMapper.selectById(UserContext.getUserId().getUserId());
        user.setNickname(dto.getNickname());
        user.setAvatar(dto.getAvatar());
        baseMapper.updateById(user);
    }


    public User getotherdetails(String userId) {
        LambdaQueryWrapper<ChatBlack> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChatBlack::getBlackedUserId,userId);
        ChatBlack one = blackService.getOne(queryWrapper);
        if(one != null){
            throw new CommonException(ResultEnum.USER_IS_BLACKED.getMsg());
        }
        return baseMapper.selectById(userId);
    }
}
